-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: textDocument/documentSymbol (Outline) #75
Conversation
Clippy seems to have found some new things to be upset about in 1.43. |
@@ -375,7 +377,8 @@ end; | |||
block_spec: code.s1("rtl(0)").name(), | |||
use_clauses: vec![], | |||
items: vec![], | |||
} | |||
}, | |||
source_range: source_range(&code, (0, 0), (3, 4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using hard coded line numbers and colums makes the tests fragile and harder to maintain. I have avoided it so far by using test helper to compute source ranges from textual searches such as finding the nth substring. In this case it would be nice to create a test helper that finds a source range between two substrings instead of hardcoding it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
When looking further into how to divide the the hierarchy I realized that there are other ranges that are required to keep track of. E.g., in order to present the ports/generics as a sub-hierarchy I need to track the range between I think that a solution would be to change the source_range field to a new struct:
This would allow the creation of the following hierarchy (each level fold-able at least in VSCode)
The alternative would be to to either change the port/generic clauses to
and similar for vectors of declarations/statements. |
I like the last option the best and the first option the least. It is better to attach the range close to where it associated and tie it together with a struct like the last option. The first option seems wierd to collect all ranges by themselves in a struct even though they are associated with different parts of the AST. |
Another alternative would be to strictly store the ranges of the tokens or the tokens themselves dividing the different parts , e.g. for an A benefit of storing the token (or a subset of the token since the value and next_state are of little use) would also be that downstream function get access to the comments related to the token. It would not capture all comments, but enough to enable "documentation" comments in e.g. Hover. This way I would claim that the information is kept with the appropriate AST object. I also think that it would introduce less logic to the parser and defer range calculation and combining of ranges to when the range is actually needed. An updated Entity declaration would then look something like:
|
I think your latest idea is good. |
Updated select AST objects with tokens and the hierarchy down to declarations/statements. The range for declarations and statements is just the range of the label or identifier, tests are not fully implemented. |
Yes as you say, a bit of testing is missing. Otherwise looks ok. |
Any update on this? |
It should be close to complete and I can free some time to finalize it. |
That would be great. |
After looking at this again I think it would be best if the AST contained higher level information rather than tokens. I like the idea of attaching a source range directly to the |
I would like to include the following in the outline:
What would the difference be between a WithPos and a WithRange? I like the concept of being able to use the range of the wrapped object to find the source. Semantically, the name would perhaps not be indicative of it describing a range but functionally it would be identical. To clarify the basic principle:
|
You are right that WithPos is already there and a WithRange is redundant. A SrcPos is already a range. |
Closing in favor of PR #114 |
Implements support for the "textDocument/documentSymbol" request.
The current implementation generate the outline of design units.
Major points:
source_range: SrcPos
field to AST design units denoting the range from the beginning of the context clause to the semi colon at the end of the design unit.vhdl_ls/document_symbol
for generating a lsp_types::DocumentSymbol. Implemented for design units.vhdl_ls/document_symbol
for getting a lsp_types::SymbolKind. Implemented for design units.A couple of questions @kraigher :
detail
field could be discussed. Currently it is used to present the object kind as in most cases there is no SymbolKind which is a direct match for the VHDL types (e.g. entity is mapped to interface).